<template>
  <div>
    <el-table
      :data="list"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children' }"
    >
      <el-table-column prop="id" label="规格编号" width="300">
      </el-table-column>
      <el-table-column prop="specsname" label="规格名称" width="300">
      </el-table-column>
      <el-table-column prop="attrs" label="规格属性" width="300">
        <template slot-scope="scope">
          <el-tag v-for="i in scope.row.attrs" :key="i">{{ i }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="300">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status == 1"
            >启用</el-button
          >
          <el-button type="default" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <el-button type="primary" @click="edit(scope.row.id)">编辑</el-button>
          <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      layout="prev, pager, next"
      :total="total"
      :page-size="size"
      background
      @current-change="changePage"
    >
    </el-pagination>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import { specsdelete } from "../../../http/api";
import { successAlert } from "../../../utils/alert";
export default {
  props:["info"],
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      list:"specs/list",
      total: "specs/total",
      size: "specs/size",
      page:"specs/page"
    }),
  },
  methods: {
    ...mapActions({
      reqList:"specs/reqList",
      reqListTwo:"specs/reqListTwo",
      changePage:"specs/changePage"
    }),
    
    edit(id) {
      this.info.isshow = true;
      this.info.isAdd = false;
      this.$emit("update", id);
    },
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          specsdelete({ id }).then((res) => {
            if (res.data.code == 200) {
              this.reqListTwo();
              successAlert(res.data.msg);
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  mounted(){
    this.reqListTwo();
  }
};
</script>

<style scoped>
.el-pagination{
  text-align:center;
}
</style>